package ym.ecrm.core.domain.systemManagement;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 权限类
 * @author Princess
 * @version 1.0
 */
@Entity
@Table(name="t_authority")
public class Authority {

	@Id 
	@GeneratedValue(generator="system-native")
	@GenericGenerator(name="system-native", strategy = "native")
	private long id;
	private String authorityName;
	private String description;
	private boolean enabled;
	
	@ManyToMany(targetEntity=Role.class,
			cascade = {CascadeType.PERSIST, CascadeType.MERGE},
            mappedBy="authorities")
	private Set<Role> roles = new HashSet<Role>();
	
	@ManyToMany(targetEntity=Resource.class,
			cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="tr_authority_resource",
			joinColumns=@JoinColumn(name="authorityId"),
			inverseJoinColumns=@JoinColumn(name="resourceId"))
	private Set<Resource> resources = new HashSet<Resource>();

	public boolean isEnabled() {
		return enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getAuthorityName() {
		return authorityName;
	}
	public void setAuthorityName(String authorityName) {
		this.authorityName = authorityName;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	public Set<Resource> getResources() {
		return resources;
	}
	public void setResources(Set<Resource> resources) {
		this.resources = resources;
	}
	
	
}
